<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    //1.创建一个xhr对象
    var xhr = new XMLHttpRequest();
    console.log(xhr.readyState);
    //2.配置xhr对象
    //参数一: method 请求方式, get / post / delete / put
    xhr.open('get', './news.json');
    console.log(xhr.readyState);
    //3.设置回调函数, 用来接收返回的响应数据
    xhr.onreadystatechange = function () {

        //console.log( xhr.readyState ); // 2 3 4
        if (xhr.readyState == 4) {
            console.log('请求到了数据', JSON.parse(xhr.responseText));
        }
    }
    //4.发送请求
    xhr.send();
</script>